<?php
	class SignupController extends CustomControllerAction
	{
		public function init() {
			parent::init();
		}

		public function indexAction() {
			
			$request = new Zend_Controller_Request_Http();
			$user_db_mgr = new UserSDBManager();

			if ($request->getParam('submit')) {

				# Verify password fields
				if ($request->getParam('password') == $request->getParam('password2')) {

					# Verify uniqueness of username
					if ($user_db_mgr->isUniqueFieldValue('username', $request->getParam('username'))) {
						
						# Insert the user into the database
						$joined = date('Y-m-d\TG:i:s');

						$attributes = array(
														"username" => $request->getParam('username'),
														"password" => sha1($request->getParam('password')),
														"email" => $request->getParam('email'),
														"phone" => $request->getParam('phone'),
														"carrier" => $request->getParam('carrier'),
														"likes" => $request->getParam('likes'),
														"dislikes" => $request->getParam('dislikes'),
														"joined" => $joined
													);

						$user = new User();
						$user->setAttributes($attributes);
						$user->save();

						print "User created";
					}
					else {
						print "Please choose another username";
					}
				}
				else {
					print "Please confirm passwords";
				}
			}
		}
	}
